package abandonedDogs;

import java.util.Scanner;

import abandonedDogs.DogDAO;

public class DogMain {
	private static final String TITLE = "강아지 DB입니다";
	private static final String MENU = "(1) 추가, (2) 전체조회, (3) 상세조회, (4) 수정, (5) 삭제, (0) 종료 ";
	
	private static final String ADDMSG = "name, sex, type, age, collar, fno, specificloc, storeddept, etc, mercykilling순 입력";
	private static final String VIEWMSG = "조회하고 싶은 강아지 번호를 입력하세요";
	private static final String UPDMSG = "수정할 강아지 번호를 입력하세요";
	private static final String DELMSG = "삭제할 강아지 번호르 ㄹ입력하세요";
	
	private static DogDAO dgs = new DogDAO();
	private static Scanner sc = new Scanner(System.in); 
	
	public static void main(String[] args) {
		System.out.println(TITLE);
		while (true) {
			System.out.println(MENU);
			switch (sc.nextInt()) {
			case 1 : newDog();
				break;
			case 2 : readDog();
				break;
			case 3 : readOneDog();
				break;
			case 4 : modifyDog();
				break;
			case 5 : removeDog();
				break;
			case 0 : sc.close();
					 System.out.println("프로그램을 종료합니다");
					 System.exit(0);
				break;
			}
		}
		
	}

	private static void removeDog() {
		System.out.println( dgs.selectDog() );
		System.out.println( DELMSG );
		String id = sc.next();
		if ( dgs.deleteDog(id) > 0 ) { System.out.println("삭제 완료"); }
		
		
	}

	private static void modifyDog() {
		System.out.println( dgs.selectDog() );
		System.out.println( UPDMSG );
		String id = sc.next();
		System.out.println( ADDMSG );
		DogVO dg = new DogVO(sc.next(), sc.next(), sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.next(), sc.nextInt(), sc.next(), sc.next());
		dg.setId(id);
		if ( dgs.updateDog(dg) > 0 ) { System.out.println("수정 완료"); }
		
	}

	private static void readOneDog() {
		System.out.println( dgs.selectDog() );
		System.out.println( VIEWMSG );
		String id = sc.next();
		System.out.println( dgs.selectDog(id) );
	}

	private static void readDog() {
		System.out.println( dgs.selectDog() );
	}

	private static void newDog() {
		System.out.println(ADDMSG);
		DogVO dg = new DogVO(sc.next(), sc.next(), sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.next(), sc.nextInt(), sc.next(), sc.next());
		int cnt = dgs.insertDog(dg);
		if ( cnt > 0 ) { System.out.println("입력 완료"); }
	}

	
}
